﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Swin_e_mon_Forms
{
    public class Item : GameEntity
    {
        private bool isStationary;

        public bool IsStationary
        {
            get { return isStationary; }
            set { isStationary = value; }
        }

        public Item(string[] ids, bool isContainter)
            : base(ids, isContainter)
        { }
    }

    [TestFixture]
    public class ItemTest
    {
        [Test]
        public void TestBasicFeatures()
        {
            Item bag = new Item(new string[] { "Bag" }, true);
            Item pen = new Item(new string[] { "Pen" }, false);

            Assert.IsTrue(bag.HasInventory);
            Assert.IsFalse(pen.HasInventory);
        }

        [Test]
        public void TestLongDesc()
        {
            Item bag = new Item(new string[] { "Bag" }, true);
            Item pen = new Item(new string[] { "Pen" }, false);

            pen.Title = "A pen title.";
            bag.Title = "A bag title.";

            pen.Description = " pen desc";
            bag.Description = "bag desc";

            bag.Inventory.AddItem(pen);
            StringAssert.Contains(pen.Title, bag.LongDescription);
            StringAssert.DoesNotContain(pen.Title, bag.Description);

            bag.Inventory.TakeItem("pen");
            StringAssert.DoesNotContain(pen.Title, bag.LongDescription);
        }

        [Test]
        public void LongDescriptionOfItem()
        {
            Item pen = new Item(new string[] { "Pen" }, false);

            pen.Title = "A pen title.";

            pen.Description = " pen desc";

            StringAssert.Contains(pen.Description, pen.LongDescription);
        }

        [Test]
        public void TestLocateEntity()
        {
            Item bag = new Item(new string[] { "Bag" }, true);
            Item pen = new Item(new string[] { "Pen" }, false);

            pen.Title = "A pen title.";
            bag.Title = "A bag title.";

            pen.Description = " pen desc";
            bag.Description = "bag desc";

            bag.Inventory.AddItem(pen);

            Assert.AreSame(pen, pen.LocateEntity("pen"));
            Assert.AreSame(pen, bag.LocateEntity("pen"));
            Assert.AreSame(bag, bag.LocateEntity("bag"));
            Assert.IsNull(pen.LocateEntity("bag"));

            bag.Inventory.TakeItem("pen");
            Assert.IsNull(bag.LocateEntity("pen"));

        }

        [Test]
        public void FailedTakeTest()
        {
            Item bag = new Item(new string[] { "Bag" }, true);
            Item pen = new Item(new string[] { "Pen" }, false);

            bag.Inventory.AddItem(pen);

            Assert.AreEqual(1, bag.Inventory._count);

            Assert.IsNull(bag.Inventory.TakeItem("blah"));

        }

        [Test]
        public void TestAccessItem()
        {
            Item bag = new Item(new string[] { "Bag" }, true);
            Item pen = new Item(new string[] { "Pen" }, false);
            Item anotherobject = new Item(new string[] { "object" }, false);

            bag.Inventory.AddItem(pen);
            bag.Inventory.AddItem(anotherobject);

            Assert.AreEqual(2, bag.Inventory._count);

            Assert.AreEqual(pen,bag.Inventory.AccessItem("pen"));

            Assert.AreEqual(2, bag.Inventory._count);
        }

        [Test]
        public void TestItemList()
        {
            Item bag = new Item(new string[] { "Bag" }, true);
            Item pen = new Item(new string[] { "Pen" }, false);
            Item anotherobject = new Item(new string[] { "object" }, false);

            pen.Title = "pen";
            anotherobject.Title = "object";

            bag.Inventory.AddItem(pen);
            bag.Inventory.AddItem(anotherobject);

            StringAssert.Contains(pen.Title, bag.Inventory.ItemList);
            StringAssert.Contains(anotherobject.Title, bag.Inventory.ItemList);
        }
    }
}

   